//
//  CriteriaTableViewCell.m
//  Criteria
//
//  Created by Jeffrey Palm on 12/25/08.
//  Copyright 2008 Navtones. All rights reserved.
//

#import "CriteriaTableViewCell.h"
#import "Util.h"

@implementation CriteriaTableViewCell

@synthesize titleLabel;
@synthesize descriptionLabel;

- (void)setText:(NSString*)str {
	str = [str capitalizedString];
	str = [str stringByReplacingOccurrencesOfString:@"\\" withString:@""];
	[super setText:str];
}

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
	if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
		// Initialization code
		
//		self.textColor = TEXT_COLOR;
		
		// we need a view to place our labels on.
		UIView *myContentView = self.contentView;
		
		/*
		 init the title label.
		 set the text alignment to align on the left
		 add the label to the subview
		 release the memory
		 */
		self.titleLabel = [Util newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:14.0 bold:YES];
		self.titleLabel.textAlignment = UITextAlignmentLeft; // default
		[myContentView addSubview:self.titleLabel];
		[self.titleLabel release];
		
		/*
		 init the url label. (you will see a difference in the font color and size here!
		 set the text alignment to align on the left
		 add the label to the subviewfile://localhost/Users/jeff/Desktop/Criteriadist.mobileprovision
		 release the memory
		 */
		self.descriptionLabel = [Util newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor lightGrayColor] fontSize:10.0 bold:NO];
		self.descriptionLabel.textAlignment = UITextAlignmentLeft; // default
		[myContentView addSubview:self.descriptionLabel];
		[self.descriptionLabel release];
	}
	
	return self;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
	
	[super setSelected:selected animated:animated];
	
	// Configure the view for the selected state
}

/*
 this function will layout the subviews for the cell
 if the cell is not in editing mode we want to position them
 */
- (void)layoutSubviews {
	
	[super layoutSubviews];
	
	// getting the cell size
	CGRect contentRect = self.contentView.bounds;
	
	// In this example we will never be editing, but this illustrates the appropriate pattern
	if (!self.editing) {
		
		// get the X pixel spot
		CGFloat boundsX = contentRect.origin.x;
		CGRect frame;
		
		/*
		 Place the title label.
		 place the label whatever the current X is plus 10 pixels from the left
		 place the label 4 pixels from the top
		 make the label 200 pixels wide
		 make the label 20 pixels high
		 
		 move it 4 pixels to the right of the image
		 */
		frame = CGRectMake(boundsX + 10 + kSearchResultImageWidth + 4, 4, 250, 20);
		self.titleLabel.frame = frame;
		
		// place the url label
		frame = CGRectMake(boundsX + 10 + kSearchResultImageWidth + 4, 28, 250, 14);
		self.descriptionLabel.frame = frame;
	}
}

- (NSString*)title {
	return titleLabel.text;
}

- (NSString*)description {
	return descriptionLabel.text;
}

- (void)setTitle:(NSString*)title {
	titleLabel.text = title;
}

- (void)setDescription:(NSString*)description {
	descriptionLabel.text = description;
}



- (void)dealloc {
	[titleLabel dealloc];
	[descriptionLabel dealloc];
    [super dealloc];
}


@end
